$(function(){
    getUserinfo()
    $('#quit').on('click',function(){
        // var confirm = layui.confirm;
        layer.confirm('确定退出?', {icon: 3, title:'提示'}, function(index){
            //do something
            localStorage.removeItem('token')
            location.href='./login.html'
            layer.close(index);
          });
     
    })
})
function getUserinfo(){
    var layer = layui.layer;
    $.ajax({
        method:'get',
        url:'/my/userinfo',
        success:function(res){
            if(res.status!==0){
                return layer.msg(res.message)
            }
            renderAvatar(res.data)
        }
    })
}
function renderAvatar(data){
    var name = data.nickname || data.username

    $('#uname').html(`欢迎${name}`)
    if(data.user_pic!==null){
        $('.layui-nav-img').attr('src',data.user_pic).show()
        $('.text-avatar').hide()
    }else{
        $('.layui-nav-img').hide()
        var first = name[0].toUpperCase()
        $('.text-avatar').html(first).show()
    }
}